package com.tuzhi.security.service;


import com.tuzhi.common.structure.SetList;

import java.util.Collection;

public interface SecurityConfig {


    SetList<String> permitList = new SetList<>();
    SetList<String> interceptList = new SetList<>();
    SetList<String> grantedAuthorityList = new SetList<>();

    default boolean isPermitUri(String uri) {
        return matchesUri(uri, permitList);
    }

    default boolean isIntercept(String uri) {
        return matchesUri(uri, interceptList);
    }

    default boolean isGrantedAuthority(String uri) {
        return matchesUri(uri, grantedAuthorityList);
    }

    default boolean matchesUri(String uri, Collection<String> set) {
        if (set != null) {
            for (String str : set) {
                if (str.contains("*")) {
                    String tmp = str.replace("*", ".*");
                    if (uri.matches(tmp)) {
                        return true;
                    }
                } else {
                    if (uri.equals(str)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

}
